package com.soso.gae.spider.memcache.api.impl;

import java.util.logging.Level;

import com.google.appengine.api.memcache.ErrorHandlers;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.soso.core.memcache.api.SyncCacheService;

public class SyncCacheServiceImpl implements SyncCacheService{
	private MemcacheService syncCache = null;
	public SyncCacheServiceImpl(){
		syncCache = MemcacheServiceFactory.getMemcacheService();
		syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
	}
	@Override
	public Object get(Object key) {
		return syncCache.get(key);
	}
	
	@Override
	public void put(Object key, Object value) {
		syncCache.put(key, value);
	}

	@Override
	public IdentifiableValue getIdentifiable(Object key) {
		Object obj=syncCache.getIdentifiable(key);
		if(obj==null)
			return null;
		IdentifiableValue iv=new IdentifiableValue();
		iv.setObj(obj);
		return iv;
	}

	@Override
	public boolean putIfUntouched(Object key,
			IdentifiableValue identifiableValue, Object value) {
		return syncCache.putIfUntouched(key, (com.google.appengine.api.memcache.MemcacheService.IdentifiableValue)identifiableValue.getObj(), value);
	}

}
